package com.hfxt.util;


import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 统一返回数据类型
 */
@Data
public class ResultBaseUtil implements Serializable {


    private static final long serialVersionUID = 2932388937708181982L;


    @ApiModelProperty(value = "是否成功")
    private Boolean success;
    @ApiModelProperty(value = "返回码")
    private Integer code;
    @ApiModelProperty(value = "返回消息")
    private String message;
    @ApiModelProperty(value = "返回Map数据")
    private Map<String, Object> data = new HashMap<String, Object>();
    @ApiModelProperty(value = "返回Object数据")
    private Object obj;

    //把构造方法私有化
    private ResultBaseUtil() {

    }

    //成功的静态方法
    public static ResultBaseUtil ok() {
        ResultBaseUtil r = new ResultBaseUtil();
        r.setSuccess(true);
        r.setCode(ResultCode.SUCCESS);
        r.setMessage("成功");
        return r;
    }

    public static ResultBaseUtil ok(String message,Object object) {
        ResultBaseUtil r = new ResultBaseUtil();
        r.setSuccess(true);
        r.setCode(ResultCode.SUCCESS);
        r.setMessage(message);
        r.setObj(object);
        return r;
    }

    public static ResultBaseUtil ok(String message) {
        ResultBaseUtil r = new ResultBaseUtil();
        r.setSuccess(true);
        r.setCode(ResultCode.SUCCESS);
        r.setMessage(message);
        return r;
    }

    //失败的静态方法
    public static ResultBaseUtil error() {
        ResultBaseUtil r = new ResultBaseUtil();
        r.setSuccess(false);
        r.setCode(ResultCode.ERROR);
        r.setMessage("失败");
        return r;
    }

    public static ResultBaseUtil error(String message) {
        ResultBaseUtil r = new ResultBaseUtil();
        r.setSuccess(false);
        r.setCode(ResultCode.ERROR);
        r.setMessage(message);
        return r;
    }

    public static ResultBaseUtil error(String message,Object object) {
        ResultBaseUtil r = new ResultBaseUtil();
        r.setSuccess(false);
        r.setCode(ResultCode.ERROR);
        r.setMessage(message);
        r.setObj(object);
        return r;
    }

    public ResultBaseUtil success(Boolean success) {
        this.setSuccess(success);
        return this;
    }

    public ResultBaseUtil message(String message) {
        this.setMessage(message);
        return this;
    }

    public ResultBaseUtil code(Integer code) {
        this.setCode(code);
        return this;
    }

    public ResultBaseUtil data(String key, Object value) {
        this.data.put(key, value);
        return this;
    }

    public ResultBaseUtil data(Map<String, Object> map) {
        this.setData(map);
        return this;
    }

    public ResultBaseUtil obj(Object obj) {
        this.setObj(obj);
        return this;
    }


}
